# print('hello')

# 方差
# 1. 计算平均值
# 2. 针对每个数字，分别计算数字和平均值的差值，再平方~
# 3. 把上述的平方值相加
# 4. 除以项数-1
# avg = (67.5 + 89.0 + 12.9 + 32.2) / 4
# total = (67.5 - avg) ** 2 + (89.0 - avg) ** 2 + (12.9 - avg) ** 2 + (32.2 - avg) ** 2
# result = total / 3
# print(result)

# a = 10
# b = a
# print(b)

# a = 10
# print(type(a))
# a = 'haha'
# print(type(a))

# e = 'My name is "jack"'
# print(e)
#
# e = '''My 'name' is "Jack"'''
# print(e)
#
# print(len(e))
#
# a1 = 'hello'
# a2 = ' world'
# print(a1 + a2)

# c1 = True
# c2 = False
# print(type(c1))
# print(type(c2))
#
# a:int = 10
# print(type(a))
# a:str = 'hello'
# print(type(a))

# a = 10
# print(f"a = {a}")
# print(f"a = {a + 10}")

# num = input('请输入一个整数：')
# print(f'您输入的数字是 {num}')
# a = int(num) + 10
# print(a)

# a = 10
# print(str(a) + 'hello')

# 输入四个小数，求四个小数的平均值
# a = input("请输入第一个数字：")
# b = input("请输入第一个数字：")
# c = input("请输入第一个数字：")
# d = input("请输入第一个数字：")
#
# a = float(a)
# b = float(b)
# c = float(c)
# d = float(d)
# avg = (a + b + c + d) / 4
#
# print(f'平均值是 {avg}')

# result = 1 + 2 * 3
# print(result)

# a = 4 ** 0.5
# print(a)
#
# b = 7 / 3
# print(b)
#
# b = 7 // 3
# print(b)
#
# b = -7 // 3
# print(b)
#
# b = 7 % 3
# print(b)

# 打印 1-10
# for i in range(1, 11):
#     print(i)

# 打印 2,4,6,8,10
# for i in range(2, 12, 2):
#     print(i)

# 打印从 10 到 1
# num = 10
# # while num >= 1:
# #     print(num)
# #     num -= 1
#
# for i in range(num, 0, -1):
#     print(i)

# 求 1 + 2 + 3 + ... + 100
# theSum = 0
# for i in range(1, 101):
#     theSum += i
# print(theSum)

# 假设我要吃5个包子
# for i in range(1, 6):
#     if i == 3 :
#         # 发现第三个包子，有一只虫~
#         continue
#     print(f'吃第{i}个包子')

# 还是要吃 5 个包子
# for i in range(1, 6):
#     if i == 3:
#         # 发现第三个包子，有半只虫
#         break
#     print(f'吃第{i}个包子')

# 给定若干个数字，求平均值(也不知道几个数字)
# 这个变量表示加和的结果
# theSum = 0
# # 这个变量表示有几个数字
# count = 0
# while True:
#     num = input('请输入一个数字(分号表示输入结束)：')
#     if num == ';':
#         #约定当用户输入 ; 的时候，表示输入结束
#         break
#     theSum += float(num)
#     count += 1
#
# print(f'平均值为{theSum / count}')

# 求 1-100的和
# theSum = 0
# for i in range(1, 101):
#     theSum += i
#
# print(theSum)

# 定义一个求和函数
# def calcSum(beg, end):
#     theSum = 0
#     for i in range(beg, end + 1):
#         theSum += i
#     print(theSum)
#
# # 调用函数
# # 求 1-100 的和
# calcSum(1, 100)
# # 求 300-400 的和
# calcSum(300, 400)
# # 求 1-1000 的和
# calcSum(1, 1000)

# def test():
#     print('hello')
#
# test()

# def test(a):
#     print(a)
#
# test(10)
# test('hello')
# test(True)

# def add(x, y):
#     return x + y
#
# print(add(10, 20))
# print(add(1.5, 2.5))
# print(add('hello', 'world'))

# 求 beg, end 这个范围的整数之和
# def calcSum(beg, end):
#     theSum = 0
#     for i in range(beg, end + 1):
#         theSum += i
#     return theSum
#
# print(calcSum(1, 100))

# def getPoint():
#     x = 10
#     y = 20
#     z = 30
#     return x, y, z
#
# a, b, c = getPoint()
# # 不要x值和y值，可以使用下划线来占位
# _,_,d = getPoint()

# x = 10

# def test():
#     print(f'x={x}') # 10，访问的是全局变量
#
# test()

# def test():
#     global x
#     x = 20
#
# test()
# print(f'x={x}')

# for i in range(1, 11):
#     print(i)
#
# print('---------------')
# print(i)


# if True:
#     x = 10
#
# print(x)


# 链式访问：一个函数的返回值，作为另一个函数的参数
# def isOdd(num):
#     if num % 2 == 0:
#         return False
#     return True
#
# def add(x, y):
#     return x + y
#
# # result = isOdd(10)
# # print(result)
#
# print(isOdd(10))
#
# def test():
#     print('hello')
#
# test()

# def a():
#     num1 = 10
#     print('函数 a')
#
# def b():
#     num2 = 20
#     a()
#     print('函数 b')
#
# def c():
#     num3 = 30
#     b()
#     print('函数 c')
#
# def d():
#     num4 = 40
#     c()
#     print('函数 d')
#
# d()

# 写一个函数，求 n 的阶乘(n 是正整数)

# def factor(n):
#     result = 1
#     for i in range(1, n + 1):
#         result *= i
#     return result
#
# print(factor(5))

# 4 = fac(3) * 4
# 3 = fac(2) * 3
# 2 = 1 * 2
# def factor(n):
#     if n == 1:
#         return 1
#     return factor(n - 1) * n
#
# print(factor(3))

# 创建列表

# 1.直接使用字面值来创建
# []就表示一个 空的列表
# a = []
# print(type(a))
#
# # 2.使用list()来创建
# b = list()
# print(type(b))

# 3.可以在创建列表的时候，在[]中指定列表的初始值
#   元素之间使用逗号来分割
# a = [1, 2, 3, 4]
# print(a)

# 4.可以在同一个列表里放不同类型的变量
# a = [1, 'hello', True, [4, 5, 6]]
# print(a)

# 使用下标来访问列表元素
# a = [1, 2, 3, 4, 5]
# print(a[2]) # 3

# a = [1, 2, 3, 4]
# a[2] = 100
# print(a)
# print(len(a))

# a = [1, 2, 3, 4]
# print(a[-1]) # -1就是倒数第一个元素
# print(a[len(a) - 1])
# print(a[1:3])# 取下标[1,3)的元素
# print(a[1:])
# print(a[::2]) # 每隔2个元素，来取一下列表中的元素

# a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
# print(a[::2]) # 1 3 5 7 9
# print(a[1:-1:2]) # 2 4 6 8

# 5.当切片中的范围超出有效下标之后，不会出现异常，而是尽可能把符合要求的元素给获取到
# print(a[1:100])

# 使用 for 遍历列表
# a = [1, 2, 3, 4, 5]
# for elem in a:
#     # print(elem)
#     elem = elem + 10
#
# print(a)

# for i in range(0, len(a)) :
#     print(a[i])

# i = 0
# while i < len(a) :
#     print(a[i])
#     i += 1

# a = [1, 2, 3, 4]
# a.append(5)
# a.append('hello')
# print(a)

# a.insert(1, 'hello')
# print(a)

a = [1, 2, 3, 4]
# print(1 in a)
# print(10 not in a)
# print(a.index(2)) # 1

# 使用pop删除列表中的最末尾的元素
# a = [1, 2, 3, 4]
# # a.pop()
# # print(a)
# a.pop(1)
# print(a)

# 使用remove方法，可以按照值来进行删除
# a = ['aa', 'bb', 'cc', 'dd']
# a.remove('cc')
# print(a)

# a = [1, 2, 3, 4]
# b = [5, 6, 7, 8]
# # c = a + b
# # print(c)
# a.extend(b)
# print(a)
# print(b)

# 创建元组
# a = ()
# print(type(a))
# b = tuple()
# print(type(b))


# a = (1, 2, 3, 4, 'hello', True, [])
# print(a)
# print(a[-1])
# print(a[1:3]) # 2 3
# for elem in a :
#     print(elem)
# print(3 in a)
# print(a.index(3)) # 2

# def getPoint():
#     x = 10
#     y = 20
#     return x, y
#
# x,y = getPoint()





